<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var str = 'oabcoefoxyozzopop'
      //创建一个空对象
      var obj = {}
      for (var i = 0; i < str.length; i++) {
        var chars = str[i]
        //  console.log(chars);
        //看空对象里是否有指定的属性名，如果没有就保存到空对象，如果有就+1
        if (obj[chars]) {
          obj[chars]++
        } else {
          obj[chars] = 1
        }
      }

      var max = 0
      var str = ''
      for (var k in obj) {
        if (obj[k] > max) {
          max = obj[k]
          str = k
        }
      }
      console.log(max, k)
    </script>
  </body>
</html>
